package wsz;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import wsz.service.AsyncComponent;

import java.util.concurrent.CompletableFuture;

/**
 * TODO：
 *
 * @author wsz
 * @desc：
 * @date 2021/12/13
 */
public class AsyncTest {

    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConf.class);
        context.start();

        AsyncComponent asyncComponent = context.getBean(AsyncComponent.class);

        while (true) {
            System.in.read();
            try {
                // 消费端默认1000
                CompletableFuture<String> sayHello = asyncComponent.sayHello("wsz", 3000);
                System.out.println("result:before");
                System.out.println("result:" + sayHello.get());
                System.out.println("result:after");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "wsz.service")
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(value = {"wsz.service"})
    static class ConsumerConf {

    }
}
